package com.xzx.mutilstram;

import com.xzx.source.RandomNumSource;
import org.apache.flink.streaming.api.collector.selector.OutputSelector;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SplitStream;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.Collections;

/**
 * @author xinzhixuan
 * @version 1.0
 * @date 2024/3/3 09:21
 */
public class MutilStream_01_SplitStream {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.getExecutionEnvironment();

        DataStreamSource<Integer> source = environment.addSource(new RandomNumSource());
        SplitStream<Integer> splitStream = source.split(new OutputSelector<Integer>() {

            @Override
            public Iterable<String> select(Integer value) {
                return value % 2 == 0 ? Collections.singleton("偶数") : Collections.singleton("奇数");
            }
        });
        splitStream.select("偶数").print("偶数");
        splitStream.select("奇数").print("奇数");

        environment.execute(MutilStream_01_SplitStream.class.getSimpleName());
    }
}
